﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for cls_tbHOADON_BANGKEHOADON
/// </summary>
public class cls_tbHOADON_BANGKEHOADON
{
	public cls_tbHOADON_BANGKEHOADON()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public static DataTable GetByF_MaCN_GetGroup(string F_MACN)
    {
        DataTable dt = new DataTable();
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        SqlParameter[] para = new SqlParameter[1];
        para[0] = new SqlParameter("@F_MACN", F_MACN);
        try
        {
            dt = connect.GetSelectCommand("tbHOADON_BANGKEHOADON_GetByF_MACN_GetGroup", para);
        }
        catch { }
        return dt;
    }
    public static DataTable GetByF_MaCN_GetGroup_orderbydesc(string F_MACN)
    {
        DataTable dt = new DataTable();
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        SqlParameter[] para = new SqlParameter[1];
        para[0] = new SqlParameter("@F_MACN", F_MACN);
        try
        {
            dt = connect.GetSelectCommand("tbHOADON_BANGKEHOADON_GetByF_MACN_GetGroup_orderbydesc", para);
        }
        catch { }
        return dt;
    }
    public static DataTable GetByF_STT(Guid F_STT)
    {
        DataTable dt = new DataTable();
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        SqlParameter[] para = new SqlParameter[1];
        para[0] = new SqlParameter("@F_STT", F_STT);
        try
        {
            dt = connect.GetSelectCommand("tbHOADON_BANGKEHOADON_GetByF_STT", para);
        }
        catch { }
        return dt;
    }
    public static DataTable GetByID(int ID)
    {
        DataTable dt = new DataTable();
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        SqlParameter[] para = new SqlParameter[1];
        para[0] = new SqlParameter("@ID", ID);
        try
        {
            dt = connect.GetSelectCommand("tbHOADON_BANGKEHOADON_GetByID", para);
        }
        catch { }
        return dt;
    }
    public static Guid GetF_STTbyID(int ID)
    {
        Guid F_STT = Guid.Empty;
        DataTable dt = new DataTable();
        dt = GetByID(ID);
        if (dt.Rows.Count > 0)
        {
            try {
                F_STT = Guid.Parse(dt.Rows[0]["F_STT"].ToString());
            }
            catch { }
        }
        return F_STT;
    }
    public static string Delete(int ID)
    {
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        object[] values = { ID };
        string[] parameters = { "@ID" };
        SqlParameter[] para = new SqlParameter[parameters.Length];
        for (int i = 0; i < parameters.Length; i++)
        {
            para[i] = new SqlParameter(parameters[i], values[i]);
        }
        try
        {
            connect.ExecuteQuery("tbHOADON_BANGKEHOADON_Delete", para);
            return "OK";
        }
        catch
        {
            return "ERR";
        }
    }
    public static string Insert(Guid F_STT, string F_KyHieuHD, string F_SoHD, DateTime F_NGAY, string F_NGUOIMUA, string F_MaSoThue, string F_MATHANG, decimal F_THANHTIEN, string F_THUE, string F_GTGT, string F_GHICHU, string F_DONVI, string F_DIACHI, string F_TIENBANGCHU, int F_LOAI, string F_HTTT, string F_MACN, bool F_DAIN, string F_TAIKHOAN, string F_MSTNMH, decimal F_CONGTIENHANG, string F_DVT, int F_SOLUONG, decimal F_DONGIA, decimal F_THANHTIEN_SLxDG, string F_NGUOIMUAHANG_KYTEN, string F_NGUOIBANHANG, int F_SOLAN_IN, int F_LOAIKHACHHANG, int F_SoHD_INT)
    {
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        object[] values = { F_STT, F_KyHieuHD, F_SoHD, F_NGAY, F_NGUOIMUA, F_MaSoThue, F_MATHANG, F_THANHTIEN, F_THUE, F_GTGT, F_GHICHU, F_DONVI, F_DIACHI, F_TIENBANGCHU, F_LOAI, F_HTTT, F_MACN, F_DAIN, F_TAIKHOAN, F_MSTNMH, F_CONGTIENHANG, F_DVT, F_SOLUONG, F_DONGIA, F_THANHTIEN_SLxDG, F_NGUOIMUAHANG_KYTEN, F_NGUOIBANHANG, F_SOLAN_IN, F_LOAIKHACHHANG, F_SoHD_INT };
        string[] parameters = { "@F_STT", "@F_KyHieuHD", "@F_SoHD", "@F_NGAY", "@F_NGUOIMUA", "@F_MaSoThue", "@F_MATHANG", "@F_THANHTIEN", "@F_THUE", "@F_GTGT", "@F_GHICHU", "@F_DONVI", "@F_DIACHI", "@F_TIENBANGCHU", "@F_LOAI", "@F_HTTT", "@F_MACN", "@F_DAIN", "@F_TAIKHOAN", "@F_MSTNMH", "@F_CONGTIENHANG", "@F_DVT", "@F_SOLUONG", "@F_DONGIA", "@F_THANHTIEN_SLxDG", "@F_NGUOIMUAHANG_KYTEN", "@F_NGUOIBANHANG", "@F_SOLAN_IN", "@F_LOAIKHACHHANG", "@F_SoHD_INT" };
        SqlParameter[] para = new SqlParameter[parameters.Length];
        for (int i = 0; i < parameters.Length; i++)
        {
            para[i] = new SqlParameter(parameters[i], values[i]);
        }
        try
        {
            connect.ExecuteQuery("tbHOADON_BANGKEHOADON_Insert", para);
            return "OK";
        }
        catch
        {
            return "ERR";
        }
    }
    public static string Update_dain_solan(int ID)
    {
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        object[] values = { ID };
        string[] parameters = { "@ID" };
        SqlParameter[] para = new SqlParameter[parameters.Length];
        for (int i = 0; i < parameters.Length; i++)
        {
            para[i] = new SqlParameter(parameters[i], values[i]);
        }
        try
        {
            connect.ExecuteQuery("tbHOADON_BANGKEHOADON_Update_dain_solan", para);
            return "OK";
        }
        catch
        {
            return "ERR";
        }
    }
    public static string Update(int ID, string F_KyHieuHD, string F_SoHD, DateTime F_NGAY, string F_NGUOIMUA, string F_MaSoThue, string F_MATHANG, decimal F_THANHTIEN, string F_THUE, string F_GTGT, string F_GHICHU, string F_DONVI, string F_DIACHI, string F_TIENBANGCHU, string F_HTTT, string F_MACN, string F_TAIKHOAN, string F_MSTNMH, decimal F_CONGTIENHANG, string F_DVT, int F_SOLUONG, decimal F_DONGIA, decimal F_THANHTIEN_SLxDG, string F_NGUOIMUAHANG_KYTEN, string F_NGUOIBANHANG, int F_SoHD_INT)
    {
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        object[] values = { ID, F_KyHieuHD, F_SoHD, F_NGAY, F_NGUOIMUA, F_MaSoThue, F_MATHANG, F_THANHTIEN, F_THUE, F_GTGT, F_GHICHU, F_DONVI, F_DIACHI, F_TIENBANGCHU, F_HTTT, F_MACN, F_TAIKHOAN, F_MSTNMH, F_CONGTIENHANG, F_DVT, F_SOLUONG, F_DONGIA, F_THANHTIEN_SLxDG, F_NGUOIMUAHANG_KYTEN, F_NGUOIBANHANG, F_SoHD_INT };
        string[] parameters = { "@ID", "@F_KyHieuHD", "@F_SoHD", "@F_NGAY", "@F_NGUOIMUA", "@F_MaSoThue", "@F_MATHANG", "@F_THANHTIEN", "@F_THUE", "@F_GTGT", "@F_GHICHU", "@F_DONVI", "@F_DIACHI", "@F_TIENBANGCHU", "@F_HTTT", "@F_MACN", "@F_TAIKHOAN", "@F_MSTNMH", "@F_CONGTIENHANG", "@F_DVT", "@F_SOLUONG", "@F_DONGIA", "@F_THANHTIEN_SLxDG", "@F_NGUOIMUAHANG_KYTEN", "@F_NGUOIBANHANG", "@F_SoHD_INT" };
        SqlParameter[] para = new SqlParameter[parameters.Length];
        for (int i = 0; i < parameters.Length; i++)
        {
            para[i] = new SqlParameter(parameters[i], values[i]);
        }
        try
        {
            connect.ExecuteQuery("tbHOADON_BANGKEHOADON_Update", para);
            return "OK";
        }
        catch
        {
            return "ERR";
        }
    }
    public static string Update_sohoadonrieng(string F_MACN, string F_SoHD, int ID, int F_SoHD_INT)
    {
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        object[] values = { F_MACN, F_SoHD, ID, F_SoHD_INT };
        string[] parameters = { "@F_MACN", "@F_SoHD", "@ID", "@F_SoHD_INT" };
        SqlParameter[] para = new SqlParameter[parameters.Length];
        for (int i = 0; i < parameters.Length; i++)
        {
            para[i] = new SqlParameter(parameters[i], values[i]);
        }
        try
        {
            connect.ExecuteQuery("tbHOADON_BANGKEHOADON_Update_sohoadonrieng", para);
            return "OK";
        }
        catch
        {
            return "ERR";
        }
    }
    public static string Update_sohoadonluontieptheo(string F_MACN, string F_SoHD, int ID, int F_SoHD_INT)
    {
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        object[] values = { F_MACN, F_SoHD, ID, F_SoHD_INT };
        string[] parameters = { "@F_MACN", "@F_SoHD", "@ID", "@F_SoHD_INT" };
        SqlParameter[] para = new SqlParameter[parameters.Length];
        for (int i = 0; i < parameters.Length; i++)
        {
            para[i] = new SqlParameter(parameters[i], values[i]);
        }
        try
        {
            connect.ExecuteQuery("tbHOADON_BANGKEHOADON_Update_sohoadonluontieptheo", para);
            return "OK";
        }
        catch
        {
            return "ERR";
        }
    }
    public static string Action_lapbangkehoadontheongay(string F_MACN,DateTime F_NGAY)
    {
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        object[] values = { F_MACN, F_NGAY };
        string[] parameters = { "@F_MACN", "@F_NGAY" };
        SqlParameter[] para = new SqlParameter[parameters.Length];
        for (int i = 0; i < parameters.Length; i++)
        {
            para[i] = new SqlParameter(parameters[i], values[i]);
        }
        try
        {
            //connect.ExecuteQuery("tbHOADON_BANGKEHOADON_lapbangkehoadontheongay", para);
            return "OK";
        }
        catch
        {
            return "ERR";
        }
    }
    public static DataTable GetBangkehoadontheongay(string F_MACN, DateTime F_NGAY)
    {
        DataTable dt = new DataTable();
        DatabaseConnect connect = new DatabaseConnect();
        // Tham so
        object[] values = { F_MACN, F_NGAY };
        string[] parameters = { "@F_MACN", "@F_NGAY" };
        SqlParameter[] para = new SqlParameter[parameters.Length];
        for (int i = 0; i < parameters.Length; i++)
        {
            para[i] = new SqlParameter(parameters[i], values[i]);
        }
        try
        {
            dt = connect.GetSelectCommand("tbHOADON_BANGKEHOADON_GetBangkehoadontheongay", para);
        }
        catch { }
        return dt;
    }
}